<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>

        // 简化操作

        // let name ="老王";
        // let age = 18;

        // let fn = function(){
        //     console.log(123);
        // }

        // // es5
        // let obj = {
        //     name:name,
        //     age:age,
        //     fn:fn,
        //     fn2:function(){
        //         console.log(this.age);
        //     }
        // }

        // console.log(obj.name,obj.age);

        // obj.fn();
        // obj.fn2();



        // ES6
        let name2 ="老王";
        let age = 18;

        let fn = function(){
            console.log(123);
        }

        // 简化对象 ， 当你属性名和变量名一致时，可以只写一个，
        // 声明函数时，可以直接写  函数名(){}
        let obj = {
            name,
            age,
            fn,
            fn2(){
                console.log(this.name);
            }
        }

        console.log(obj.name,obj.age);
        obj.fn();

        obj.fn2();






    </script>
</body>
</html>